<template>
	<Layout class="p-5 bg-white">
		<Form :label-width="150">
			<row>
				<Col span="8">
				<FormItem class="w-100" label="订单类型名字">
					<label>{{payCost.typeName}}</label>
				</FormItem>
				<FormItem class="w-100" label="订单类型价格/元">
					<Input v-model="payCost.price" />
				</FormItem>
				
				
				<FormItem>
					<Button @click="submit" type="primary">提交</Button>
					<Button @click="cancel" style="margin-left: 8px">取消</Button>
				</FormItem>
				</Col>
			</row>
		</Form>
	</Layout>
</template>

<script>
	export default {
		data: function() {
			return {
				orderTypeId: 0,
				payCost: {}
			};
		},
		methods: {
			cancel: function() {
				this.$tabs.close();
			},
			submit: function() {
				let self = this;
				if (this.$data.payCost.price.length == 0) {
					this.message.error("价格必须输入");
					return;
				}
				
				let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
				
				if (!reg.test(this.$data.payCost.price)){
					this.message.error('保证金金额的输入格式不正确,请确认!');
					return ;
				}
				let newPrice = self.payCost.price * 100
				this.http.put({
					url: "/pay-cost/info",
					param: {
						price: newPrice,
						orderTypeId: this.$data.orderTypeId
					}
				}).then(() => {
					self.message.info("修改成功");
					self.$tabs.close();
					this.$router.push({
						name: "payCost",
						params: {}
					});
				});
			},
			init: function() {
				let self = this;
				self.http.get({
					url: "/pay-cost/info",
					param: {
						orderTypeId: self.$data.orderTypeId
					}
				}).then(data => {
					self.$data.payCost = data;
					this.$data.payCost.price = (data.price)/100;
				});
			},
		},
		created: function() {
			this.$data.orderTypeId = this.$route.params.orderTypeId;
			this.init();
		},
	}
</script>

<style>
</style>
